<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="${basePath}/public/css/adminlogin.css">
    <script type="text/javascript" src="${basePath}/public/js/jquery.min.js"  ></script>
    <script type="text/javascript">



        function login() {
            var name = $("#username").val();
            var password = $("#password").val();
            var code = $("#code").val();

            if(name==""){
                alert("请输入用户名");
                name.focus();
                return false;
            }

            if(password==""){
                alert("请输入密码");
                password.focus();
                return false;
            }

            if(code==""){
                alert("请输入验证码");
                code.focus();
                return false;
            }

            $.ajax({
                url:"${basePath}/admin/adminUser",
                type:"get",
                data:{
                    username:name,
                    password:password,
                    code:code
                },

                success:function (resultJson) {
                    if (resultJson.status==1){
                        alert(resultJson.msg);
                        window.location.href="${basePath}/admin/adminUser/index";
                    }if (resultJson.status==2){
                        alert(resultJson.msg);
                    } else {
                        alert(resultJson.msg);
                    }
                }
            })
        }

        //表单验证
        function loginsubmit(){
            alert(1)
            var username = $("#username").val();
            var password = $("#password").val();
            var code = $("#code").val();
            if(username==""){
                alert("请输入用户名");
                username.focus();
                return false;
            }

            if(password==null){
                alert("请输入密码");
                password.focus();
                return false;
            }

            if(code==null){
                alert("请输入验证码");
                code.focus();
                return false;
            }

            return true;
        }
    </script>
</head>
<body>
<form action="" method="post" enctype="application/x-www-form-urlencoded" onsubmit="return loginsubmit()">
    <div class="login-main">
        <div class="login-header">
            登录
        </div>
        <div class="item-box">
            <img src="${basePath}/public/images/login-user.png" class="img">
            <input type="text" name="username"  id="username" placeholder="用户名">
        </div>
        <div class="item-box">
            <img src="${basePath}/public/images/login-pass.png" class="img">
            <input type="password" name="password" id="password" placeholder="密码">
        </div>

        <div class="item-code-box">
            <div class="item-box1">
                <img src="${basePath}/public/images/login-pass.png" class="img">
                <input type="text" name="code" id="code" placeholder="验证码">
            </div>
            <img id="codeImg" alt="验证码" src="${basePath}/shopping/index/code" onclick="changeImg()" style="width: 117px;height: 34px;margin-top: 4px;margin-left: 19px;"/>
        </div>

        <div class="item-box" style="border: 0px;margin-top: 15px;">
            <input  type="button" value="登录" class="btn" style="border: 0px;" onclick="login()"/>
        </div>
        <div class="item-box" style="border: 0px;margin-top: 15px;">
            <a href="${basePath}/home/homepage/index" class="btn" style="background: #2aef6c;">返回首页</a>
        </div>
    </div>
</form>
</body>
</html>
